<?php

	class sqlResult
	{
		private $res;
		
		function __construct($resultset) {
			$this->res = $resultset;
		}
		
		function next() {
			return mysqli_fetch_array($this->res);
		}
	}

	class sqlConnection
	{		
		private $con = null;
		
		function __construct($db, $user, $password, $database) {
			
			//Versuche dich mit einer Datenbank zu verbinden.
			if ($database != null && $database != "") {
				$this->con = mysqli_connect($db, $user, $password, $database);
			} else {
				$this->con = mysqli_connect($db, $user, $password);
			}	
			
			
			//Bei einem Fehler...
			if (mysqli_connect_errno())
			{				
//				echo "Failed to connect to MySQL: " . mysqli_connect_error() . "<br>";	
						
			} else {
				
//				echo "connected.<br>";
				
			}
			
		}		
	
		function doSql($sql) {
			$result =  mysqli_query($this->con,$sql) ;
			
//			echo "Query gesendet: " . $sql . "<br>";
			
			if (!$result)
			{
//				echo "Query error: " . mysqli_error($this->con) . "<br>";
			}
			
			return new sqlResult($result);
		}
	}
	
?>